package vboot.core.module.mon.job.log;

import vboot.core.common.api.R;
import vboot.core.common.dao.Sqler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("mon/job/log")
public class MonJobLogApi {

    private String table = "mon_job_log";

    @GetMapping
    public R get(String name) {
        Sqler sqler = new Sqler("t.id,t.name,t.sttim,t.entim,t.ret", table);
//        XreqUtil.setPageParam(sqler);
        sqler.addLike("t.name", name);
        sqler.addOrder("t.entim desc");
        System.out.println(sqler.getSql());
        return R.ok(service.findPageData(sqler));
    }

    @GetMapping("one/{id}")
    public R getOne(@PathVariable String id) {
        return R.ok(service.findOne(id));
    }

    @DeleteMapping("all")
    public R deleteAll() {
        service.deleteAll();
        return R.ok();
    }

    @DeleteMapping("{ids}")
    public R delete(@PathVariable String[] ids) {
        return R.ok(service.delete(ids));
    }

    @Autowired
    private MonJobLogService service;
}
